package com.hpli.trigger.job;


import com.hpli.domain.strategy.model.valobj.StrategyAwardStockKeyVO;
import com.hpli.domain.strategy.service.IRaffleStock;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author: 汀
 * @CreateTime: 2025-03-31
 * @Description: 更新奖品库存任务
 * @Version: 1.0
 */

@Slf4j
@Component()
public class UpdateAwardStockJob {

    @Resource
    private IRaffleStock raffleStock;

    @Scheduled(cron = "0/5 * * * * ?")
    public void exec() {
        try {
            StrategyAwardStockKeyVO strategyAwardStockKeyVO = raffleStock.takeQueueValue();
            if (null == strategyAwardStockKeyVO) return;
            raffleStock.updateStrategyAwardStock(strategyAwardStockKeyVO.getStrategyId(), strategyAwardStockKeyVO.getAwardId());
        } catch (InterruptedException e) {
            log.error("定时任务，更新奖品消耗库存失败", e);
        }
    }
}
